package org.yu.team2023.flashdays.registries;


import lombok.RequiredArgsConstructor;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
@RequiredArgsConstructor
public abstract class LookupDataProvider<T> implements RegistrySetBuilder.RegistryBootstrap<T> {
    protected final String modid;
    BootstapContext<T> bootstapContext;

    protected  <B> ResourceKey<B> makeKey(String name, ResourceKey<Registry<B>> type) {
        return ResourceKey.create(type,new ResourceLocation(modid,name));
    }

    public <D> Holder<D> getData(ResourceKey<Registry<D>> regKey, ResourceKey<D> resourceKey) {
        return bootstapContext.lookup(regKey).getOrThrow(resourceKey);
    }

    @Override
    public void run(@NotNull BootstapContext<T> bootstapContext) {
        this.bootstapContext = bootstapContext;
        this.bootstrap(bootstapContext);
    }

    protected abstract void bootstrap(BootstapContext<T> context);
}
